import { isString, isFunction, isObject, isNumber } from 'lodash-es'

export default {
  name: 'CustomRender',
  functional: true,
  props: {
    render: { type: Function, required: true }
  },
  render(h, ctx) {
    if (!isFunction(ctx.props.render)) {
      console.warn('[CustomRender] render不是一个函数')
      return h('span', '')
    }

    const vnode = ctx.props.render(h, ctx.data.attrs, ctx.listeners, ctx)

    if (isString(vnode) || isNumber(vnode)) {
      return h('span', vnode)
    } else if (isObject(vnode)) {
      return vnode
    } else {
      console.warn('[CustomRender] render方法的返回参数不合法')
      console.warn(vnode)
      return h('span', '')
    }
  }
}
